export function getDetail(goodsId) {
  return axios.get('/api/detail', {
    params: {
      iid: goodsId
    }
  })
}

/**
 * 获取推荐数据
 * @returns {AxiosPromise<any>}
 */
export function getRecommend() {
  return axios.get('/api/recommend')
}

/**
 * 商品基本信息
 */
export class GoodsInfo {
  constructor(itemInfo, columns, services) {
    // 检查是否要更新columns的数据
    this.changeColumns(columns, services)

    this.title = itemInfo.title
    this.desc = itemInfo.desc
    this.lowNowPrice = itemInfo.lowNowPrice
    this.oldPrice = itemInfo.oldPrice
    this.discount = itemInfo.discountDesc
    this.columns = columns
    this.services = services
    this.highNowPrice = itemInfo.highNowPrice
  }

  /**
   * 将Services中没有图标的数据添加到columns中
   * @param cloumns
   * @param services
   * @returns {*}
   */
  changeColumns(cloumns, services) {
    services.map((service, index) => {
      if (!service.icon) {
        cloumns.push(service.name)
        services.splice(index, 1)
      }
    })
  }
}

/**
 * 店铺基本信息
 */
export class ShopInfo {
  constructor(shopInfo) {
    this.logo = shopInfo.shopLogo
    this.name = shopInfo.name
    this.fans = shopInfo.cFans
    this.sells = shopInfo.cSells
    this.score = shopInfo.score
    this.goodsCount = shopInfo.cGoods
    this.shopUrl = shopInfo.shopUrl
    this.allGoodsUrl = shopInfo.allGoodsUrl
  }
}

/**
 * 获取商品参数
 */
export class GoodsParam {
  constructor(itemParams) {
    this.image = itemParams.info.imacr ? info.image[0] : ''
    this.infos = itemParams.info.set
    this.sizes = itemParams.rule.tables
  }
}